﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using MpSoft.Library.BUSS.Categories;
using MpSoft.Library.DTO;

namespace MpSoft.Web.AdminCP.Controls.Category
{
    public partial class CategoryList : System.Web.UI.UserControl
    {
        #region Var
        #endregion

        #region Method

        private string GetListCategory(ref int index,string space, List<Library.DTO.Category> listCate)
        {
            if (listCate != null)
            {
                StringBuilder sb = new StringBuilder(32);
                foreach(var obj in listCate)
                {
                    index++;
                    sb.Append("<tr>");
                    sb.Append("<td>" + index + "</td> <td><input data-color='blue' data-skin='square' class='icheck-me' type='checkbox' name='check' value='" + obj.CategoryID + "'></td>");
                    sb.Append("<td><a href='?mod=categoryedit&itemid=" + obj.CategoryID + "'>" + space + obj.CategoryName + "</a></td><td>" + GetNameModule(obj.TypeCode) + "</td><td class='tb-gen-1'>" + (obj.IsActive ? "<span title='" + obj.CategoryID + "' class='label label-satgreen' data-act='1' >Đã bật</span>" : "<span title='" + obj.CategoryID + "' class='label label-lightred' data-act='0'>Chưa bật</span>") + "</td>");
                    sb.Append("<td class='tb-gen-1'><input type='text' name='order' class='tb-text' title='" + obj.CategoryID + "' value='" + obj.SortOrder + "' /><span class='tb-val-order'>" + obj.SortOrder + "</span></td>");
                    sb.Append("<td class='tb-gen-1'><a href='?mod=categoryedit&itemid=" + obj.CategoryID + "' class='btn' rel='tooltip' title='Sửa'><i class='fa fa-edit'></i></a>");
                    sb.Append("<a href='" + obj.CategoryID + "' class='btn Delete' rel='tooltip' title='Xóa'><i class='fa fa-times'></i></a>");
                    sb.Append("</td><td>" + obj.ParentID + "</td></tr>");
                    var subListCate = CategoryBUSS.Category_ByParentID(obj.CategoryID, null, null, 0);
                    sb.Append(GetListCategory(ref index, "--|", subListCate));
                }
                return sb.ToString();
            }
            return "";
        }

        private string GetNameModule(string keyModule)
        {
            switch (keyModule)
            {
                case "san-pham":
                    return "Sản phẩm";
                case "tin-tuc":
                    return "Tin tức";
                case "bai-viet":
                    return "Bài viết";
                case "download":
                    return "Download";
                case "gallery":
                    return "Thư viện ảnh";
                case "system":
                    return "Hệ thống";
                default:
                    return "";
            }
        }

        protected string GetListCate()
        {
            
            int index = 0;
            var listCatgory = CategoryBUSS.Category_ByParentID(0, null, null, 0);
            return GetListCategory(ref index, "", listCatgory);
        }

        #endregion

        #region Event
       
        protected void Page_Load(object sender, EventArgs e)
        {
            Categories.DdlCategories.CssClass = "";
            Categories.DdlCategories.Attributes.Add("style", "width:auto");
            
        }
        
        #endregion

        #region Properties
        #endregion
    }
}